package com.example.a2032.Utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferenceUtils {
    public static final int  tempUnitF = 1;
    public static final int   tempUnitC = 0;
    public static final String KEY_TimeMode = "TimeMode";
    public static final String KEY_Language = "KEY_Language";
    public static final String KEY_NotifyMode = "KEY_NotifyMode";
    public static final String KEY_BrightLevel = "BrightLevel";
    public static final String KEY_VoiceLevel = "KEY_VoiceLevel";
    public static final String KEY_TelLimit = "KEY_TelLimit";
    public static final String KEY_WatchFace = "KEY_WatchFace";
    private static final String spName = "jstyle_watch";
    public static final String watchId = "watchId";
    public static final String KEY_LastLocation= "KEY_LastLocation";
    public static final String KEY_StepGoal= "KEY_StepGoal";
    public static final String KEY_StepGoalTips1= "KEY_StepGoalTips1";
    public static final String KEY_StepGoalTips2= "KEY_StepGoalTips2";
    public static final String KEY_StepGoalTipsDate= "KEY_StepGoalTipsDate";
    public static final String KEY_SleepPeriodStart= "KEY_SleepPeriodStart";
    public static final String KEY_SleepPeriodEnd= "KEY_SleepPeriodEnd";
    public static final String KEY_PsmStart= "KEY_PsmStart";
    public static final String KEY_PsmShunDowm= "KEY_PsmShunDowm";
    public static final String KEY_LastUploadHistoryDate= "KEY_LastUploadHistoryDate";
    public static final String KEY_LastUploadSleepDate= "KEY_LastUploadSleepDate";
    public static final String KEY_LastUploadStepDate= "KEY_LastUploadStepDate";
    public static final String KEY_LastUploadEcgDate= "KEY_LastUploadEcgDate";
    public static final String KEY_TempUnit= "KEY_TempUnit";
    private static SharedPreferences sp;
    public static final String DefaultCountryCode = "0086-";
    public static void init(Context context) {
        sp = context.getSharedPreferences(spName, Activity.MODE_PRIVATE);
    }

    public static SharedPreferences getSharedPreferences() {
        return sp;
    }

    public static void setSpBoolean(String name, boolean bool) {

        getSharedPreferences().edit().putBoolean(name, bool).commit();
    }

    public static boolean getSpBoolean(String name) {
        return getSharedPreferences().getBoolean(name, false);
    }

    public static boolean getBoolean(String name, boolean defaultValue) {
        return getSharedPreferences().getBoolean(name, defaultValue);
    }

    public static void setSpString(String name, String value) {
        getSharedPreferences().edit().putString(name, value).commit();
    }

    public static String getSpString(String name) {
        return getString(name, null);
    }

    public static String getString(String name, String defaultValue) {
        return getSharedPreferences().getString(name, defaultValue);
    }

    public static void setSpInteger(String name, int value) {
        getSharedPreferences().edit().putInt(name, value).commit();
    }

    public static int getInteger(String name, int defaultValue) {
        return getSharedPreferences().getInt(name, defaultValue);
    }

    public static int getSpInteger(String name) {
        return getInteger(name, -1);
    }

    public static void setSpFloat(String name, float value) {
        getSharedPreferences().edit().putFloat(name, value).commit();
    }

    public static float getSpFloat(String name) {
        return getFloat(name, 0.0f);
    }

    public static float getFloat(String name, float defaultValue) {
        return getSharedPreferences().getFloat(name, defaultValue);
    }
}
